package a;

import java.util.Scanner;

public class PhanSo {
	int ts,ms;
	PhanSo(){};
	Scanner input = new Scanner(System.in);
	public void inputdata()
	{
		System.out.println("Nhap Tu So");
		this.ts=input.nextInt();
		System.out.println("Nhap Mau So");
		this.ms=input.nextInt();
		if((ts==0)||(ms==0)) System.out.println("Tu so va mau so phai khac 0");
		this.ts=ts;
		this.ms=ms;
		if( ms < 0)
		{
			
		}	
	}
	public int UCLN(int a,int b)
	{
		if(a==0||b==0)
		{
			return a+b;
		}
		while(a!=b)
		{
			if(a>b)
				a = a-b;
			else 
				b= b -a;
		}
		return a;
	}
	
	// Toi Gian Phan So
	public void ToiGianPS()
	{
	int i = UCLN(ts,ms);
	this.ts = this.ts/i;
	this.ms = this.ms/i;
	}
	public PhanSo Tong(PhanSo f)
	{
		PhanSo ps = new PhanSo();
		ps.ts = this.ts*f.ms +f.ts*this.ms;
		ps.ms=this.ms*f.ms;
		ps.ToiGianPS();
		return ps;
	}
	public PhanSo Hieu(PhanSo f)
	{
		PhanSo ps = new PhanSo();
		ps.ts = this.ts*f.ms -f.ts*this.ms;
		ps.ms=this.ms*f.ms;
		ps.ToiGianPS();
		return ps;
		
	}
	public PhanSo Tich(PhanSo f)
	{
		PhanSo ps = new PhanSo();
		ps.ts=this.ts*f.ms;
		ps.ms=this.ms*f.ms;
		ps.ToiGianPS();
		return ps;
		
	}
	public PhanSo Thuong(PhanSo f)
	{
		PhanSo ps = new PhanSo();
		ps.ts=this.ts*f.ms;
		ps.ms=this.ms*f.ts;
		ps.ToiGianPS();
		return ps;
		
	}
	public void OutputData(String s)
	{
		if (ts!=ms)
		{
			if(ts!=0)
				System.out.println(s+" "+ts+"/"+ms);
			else
				System.out.println(s+ "0");
		}
		else System.out.println(s+"1");
	}
	public static void main(String[] args)
	{
		PhanSo ps1 = new PhanSo();
		PhanSo ps2 = new PhanSo();
		System.out.println(" Moi nhap phan so 1");
		ps1.inputdata();
		System.out.println(" Moi nhap phan so 2");
		ps2.inputdata();
		ps1.Tong(ps2).OutputData(" Tong 2 phan so la:");
		ps1.Hieu(ps2).OutputData(" Hieu 2 phan so la:");
		ps1.Tich(ps2).OutputData(" Tich 2 phan so la:");
		ps1.Thuong(ps2).OutputData(" Thuong 2 phan so la:");
		
	}
}

